package GA;

public class ChromosomePair 
{
	/**
	 * The Y-Chromosome is the "male" gene, which is the "action"-gene, because boys always plays action-like games.
	 */
//	public int[] YChromosome;
	public Binary[] YChromosome;
	/**
	 * The X-Chromosome is the "female" gene, which is the "wiseness"-gene, because girls always tries to find an non-violent (or action-filled) solution - call it a wise solution.
	 */
//	public int[] XChromosome;
	public Binary[] XChromosome;
	
	ChromosomePair father = null;
	ChromosomePair mother = null;
	
	public static final int actionLength = 10;
	public static final int wisenessLength = 9;
	public static final int length = actionLength+ wisenessLength;
	
	public ChromosomePair(int[] values, int[] js)
	{
//		YChromosome = new int[actionLength];
//		XChromosome = new int[wisenessLength];
		YChromosome = new Binary[actionLength];
		XChromosome = new Binary[wisenessLength];
		
		int i = 0;
		for(int value : values)
		{
			YChromosome[i++] = new Binary(value);
//			YChromosome[i++] = value;
		}
		
		i = 0;
		for(int value : js)
		{
			XChromosome[i++] = new Binary(value);
//			XChromosome[i++] = value;
		}
	}
	
	private ChromosomePair() 
	{
		
	}

	public ChromosomePair clone()
	{
		ChromosomePair g = new ChromosomePair();
		g.YChromosome = new Binary[actionLength];
		
		for(int i = 0; i < actionLength; i++)
		{
			g.YChromosome[i] = new Binary(this.YChromosome[i].getInteger());
		}
		g.XChromosome = new Binary[wisenessLength];
		
		for(int i = 0; i < wisenessLength; i++)
		{
			g.XChromosome[i] = new Binary(this.XChromosome[i].getInteger());
		}
		
		return g;
	}

	public void inheritance(ChromosomePair father,
			ChromosomePair mother)
	{
		this.father = father;
		this.mother = mother;
	}
	
	public void update()
	{
		for(Binary b : YChromosome)
		{
			b.correct();
		}
		for(Binary b : XChromosome)
		{
			b.correct();
		}
		
	}
	
	private static int inher = 0;
	@Override
	public String toString()
	{
		String str = "";
		for(Binary b : YChromosome)
		{
			str = str + b.getInteger()+",";
		}
		str = str.substring(0,str.length()-1)+"-";
		for(Binary b : XChromosome)
		{
			str = str + b.getInteger()+",";
		}
		str = str.substring(0,str.length()-1);
		
		if(father!=null && mother!=null && inher == 0)
		{
			inher = 1;
			str = str+" father: "+father.toString()+" mother: "+mother.toString();
			inher = 0;
		}
			
		
		
		return str;
	}
}
